package controllers

import (
	"fmt"
	beego "github.com/beego/beego/v2/server/web"
	"reflect"
)

type RegController struct {
	beego.Controller
}

func (r *RegController) Get() {
	name := r.Ctx.Input.Param(":name")
	r.Ctx.Output.Body([]byte("正则路由之Get请求，获取的参数name = " + name))
}

func (r *RegController) Post() {
	name := r.Ctx.Input.Param(":name")
	r.Ctx.Output.Body([]byte("正则路由之Post请求，获取的参数name = " + name))
}

func (r *RegController) Put() {
	name := r.Ctx.Input.Param(":name")
	age := r.Ctx.Input.Param(":age")
	r.Ctx.WriteString(fmt.Sprintf("%v，%v，%v，%v", name, reflect.TypeOf(name), age, reflect.TypeOf(age)))
}

func (r *RegController) Patch() {
	// 文件名称
	path := r.Ctx.Input.Param(":path")
	// 文件后缀
	ext := r.Ctx.Input.Param(":ext")
	filePath := fmt.Sprintf("./static/img/%v.%v", path, ext)
	r.Ctx.Output.Download(filePath, "img."+ext)
}
